<template>
  <div class="digital-cockpit">
    <!-- 顶部导航 -->
    <van-nav-bar class="nav-bar">
      <template #title>
        <span class="nav-title">我的审核</span>
      </template>
    </van-nav-bar>
    <!-- 我的审核 -->
    <div class="digital-list" v-if="activeTab==3">
      <div v-if="reviewlist.length>0">
      <div class="digital-item" v-for="(item, index) in reviewlist" :key="index">
        <!-- 数字人标题区域 -->
        <div class="digital-header">
          <div class="header-left">
            <van-image
                :src="getIcon(item.type)"
                alt="avatar"
                class="avatar"
                round
            />
            <div class="title-info">
              <h3 class="digital-title">{{ item.name }}</h3>
            </div>
          </div>
        </div>
        <van-divider class="h-divider" />
        <span><van-tag
            plain
            type="primary"
            v-for="(profession, index) in item.professional"
            :key="index"
            style="margin-right: 4px;margin-bottom: 2px">
                        {{ profession }}
                      </van-tag>
                      </span>
        <p class="digital-desc">{{ item.description }}</p>

        <!-- 数字人信息卡片 -->
        <div class="info-card">
          <div class="info-row header-row">
            <div class="info-col">能力类型</div>
            <div class="info-col">来源</div>
            <div class="info-col">申请人</div>
            <div class="info-col">申请时间</div>
          </div>
          <div class="info-row content-row">
            <div class="info-col" style="font-size: 15px">{{ showtype(item.type) }}</div>
            <div class="info-col" style="font-size: 15px">{{ item.source }}</div>
            <div class="info-col" style="font-size: 15px">{{ item.realname }}</div>
            <div class="info-col" style="font-size: 12px">{{ item.applytime }}</div>
          </div>
        </div>

        <!-- 操作按钮区域 -->
        <div class="action-buttons">
          <span class="cancel-sub" />
          <div class="right-buttons">

            <span class="cancel-sub">
              <van-button
                  class="btn-pause"
                  size="small"
                  @click="ThroughClick(item,false)">
                驳回
              </van-button>
               <van-button
                   class="btn-executor"
                   size="small"
                   @click="ThroughClick(item,true)">
                通过
              </van-button>
          </span>
          </div>
        </div>
      </div>
      <van-pagination v-model="pageNo" :total-items="total" :items-per-page="pageSize" @change="init"/>
      </div>
      <div v-else>
         <van-empty description="暂无数据" v-if="reviewlist.length==0"/>
      </div>
    </div>
  </div>
</template>

<script>
import { getAction } from '@/api'
export default {
  data() {
    return {
      activeTab: 3,
      reviewlist: [],
      total:0,
      pageNo:1,
      pageSize:9,
      item:'',
    };
  },
  mounted() {
    if(this.$route.params.activeTab){
      this.activeTab=this.$route.params.activeTab
    }
    this.init()
  },
  methods: {
    ThroughClick(item, value) {
      getAction('/sys/cockpitReview/Through',{id:item.id,marketId:item.marketId,value: value}).then(res => {
        if (res.code === 200) {
          this.$toast.success('操作成功');
          this.init();
        } else {
          this.$toast.fail(res.msg);
        }
      });
    },
    init(){
      if(this.activeTab==3){
        this.pageNo=1
        this.pageSize=9
        getAction('/sys/cockpitReview/approvallist', {pageNo: this.pageNo, pageSize: this.pageSize,activeTag:this.activeTag}).then(res=>{
          this.reviewlist = res.result.records.map(item => {
            // 将 professional 字段从字符串转换为数组
            return {
              ...item,
              professional: item.professional ? JSON.parse(item.professional) : []
            };
          });

          this.total = res.result.total;  // 总条数
        })
      }
    },
    getIcon(type) {
      if (type === 'api') {
        return require('@/assets/api.png'); // API 对应图标
      } else if (type === 'agent') {
        return require('@/assets/zhinengti.png'); // Agent 对应图标
      }
      return require('@/assets/api.png'); // 默认图标
    },
    showtype(val){
      if(val=='agent'){
        return 'Agent'
      }else{
        return 'API接口'
      }
    },
  }
};
</script>

<style scoped>
::v-deep .van-nav-bar__content{
  background: #F4FCFF;
}

.message-content {
  text-align: left;
  white-space: pre-line;
  white-space: pre-wrap;
}
/deep/ .van-tag--primary.van-tag--plain{
  background: #f2fffd;
  color: #26B1A1;
}
.nav-title {
  font-size: 16px;
  font-weight: bold;
  color: #26B1A1;
  letter-spacing: 0.5px;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  cursor: pointer;
  opacity: 0.7; /* 初始半透明 */
  transition: opacity 0.3s; /*  hover 动画 */
}

.copy-btn:hover {
  opacity: 1; /* hover 时完全显示 */
}
/deep/ .van-overlay{
  background-color: rgb(0 0 0 / 15%) !important;
}
/deep/.van-switch{
  font-size: 16px !important;
}
.digital-cockpit {
  /*background-color: #f7f8fa;*/
  background-color: #fbfbfb;
  min-height: 100vh;
}

/* 导航栏样式 */
.nav-bar {
  background-color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* 标签栏样式 */
.tab-bar {
  background-color: #fff;
  margin-bottom: 14px;
}

.tab-title {
  font-size: 16px;
  font-weight: 500;
}

/deep/.van-tabs__line {
  background-color: #27C2AD !important;
}
/deep/.van-tab--active{
  color: #27C2AD !important;
}

/* 搜索框样式 */
.search-box {
  padding: 0 16px 12px;
}

.search-input {
  background-color: white !important;
  border-radius: 5px;
  padding: 5px 0px !important;
}

.van-search__content{
  background-color: white !important;
}

/* 数字人列表样式 */
.digital-list {
  margin-bottom: 8vh;
  padding: 10px 16px;
}

.digital-item {
  background-color: #fff;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 数字人标题区域 */
.digital-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
}

.avatar {
  width: 26px;
  height: 26px;
  margin-right: 12px;
}

.title-info {
  min-width: 0;
}

/deep/.van-divider{
  margin: 0px 0px 6px 0px;
}

.digital-title {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.digital-desc {
  padding-bottom: 8px;
  font-size: 14px;
  color: #c0c4c8;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
}

.switch-text {
  position: relative;
  margin-left: 8px;
  font-size: 13px;
  color: #666;
  bottom: 2px;
  right: 8px;
}

/* 信息卡片样式 */
.info-card {
  width: 100%;
  border: 1px solid #e5e6eb;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 6px;
}

.info-row {
  display: flex;
  width: 100%;
}

.header-row {
  background-color: #f4f8f9;
  color: #909399;
  font-size: 13px;
  border-bottom: 1px solid #e5e6eb;
}

.content-row {
  margin-top: -20px;
  background-color: #f5f7fa;
  color: #303133;
  font-size: 14px;
}

.info-col {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  position: relative;
}

.info-col:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 15%;
  height: 70%;
  width: 1px;
  background-color: #e5e6eb;
}
/* 操作按钮样式 */
.action-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cancel-sub {
  color: #f53f3f;
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}

.right-buttons {
  display: flex;
  gap: 8px;
}

.btn-pause {
  background-color: #f53f3f;
  color: #fff;
  border-radius: 32px;
}

.btn-executor {
  background-color: #27C2AD !important;
  color: #fff;
  border-radius: 18px;
}

.btn-more {
  background-color: #e8f3ff;
  color: #1989fa;
  border-radius: 32px;
}

/* 适配小屏幕 */
@media (max-width: 375px) {
  .info-cell {
    flex: 0 0 50%;
  }

  .info-cell:nth-child(2)::after {
    display: none;
  }

  .info-cell:nth-child(3)::after {
    display: block;
  }
}


/* 能力助手 */


.chat-container {
  height: 84vh; /* 占满屏幕高度 */
  display: flex;
  flex-direction: column;
  background-color: #f7f8fa;
  overflow: hidden;
}

/* 消息列表：可滚动， flex占满剩余空间 */
.messages {
  flex: 1;
  padding: 20px 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;

/* 滚动条美化（仅WebKit内核） */
&::-webkit-scrollbar {
   width: 6px;
 }
&::-webkit-scrollbar-thumb {
   background-color: #ddd;
   border-radius: 3px;
 }
}

.message {
  display: flex;
  align-items: center;

}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 8px;
}
.message-content {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 4px;
  max-width: 100%;
  word-wrap: break-word;
  line-height: 1.8;
}
.message.user .message-content {
  max-width: calc(100% - 20px); /* 右边预留20px间距 */
  background-color: #e8f3ff;
  color: black;
  border-top-right-radius: 0;
  padding: 10px 15px;
  margin-left: auto; /* 右对齐 */
}
.message.assistant .message-content {
  max-width: calc(100% - 50px); /* 40px头像 + 10px间距 */
  background-color: #fff;
  color: #333;
  border-top-left-radius: 0;
  padding: 10px 15px; /* 增加内边距，让内容更清晰 */
}


/* 头像样式：圆形，固定大小 */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
  object-fit: cover; /* 避免图片拉伸 */
}



/* 输入区域：固定底部，背景白色 */
.input-footer {
  padding: 15px;
  background-color: #fff;
  border-top: 1px solid #eee;
}

/* 输入表单：flex布局，输入框自适应 */
.input-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

/* 输入框：圆角、无边框、内边距 */
.input-box {
  flex: 1;
  padding: 12px 20px;
  border: 1px solid #eee;
  border-radius: 25px;
  outline: none;
  font-size: 14px;
  transition: border-color 0.3s;

&:focus {
   border-color: #07c160; /* 聚焦时边框变品牌色 */
 }

&:disabled {
   background-color: #f5f5f5;
   cursor: not-allowed;
 }
}

/* 发送按钮：无背景，图标垂直居中 */
.send-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* 发送图标：大小调整，禁用时灰化 */
.send-icon {
  width: 28px;
  height: 28px;
  vertical-align: middle;
  transition: opacity 0.3s;
}

.send-icon-disabled {
  opacity: 0.5; /* 禁用时图标半透明 */
  cursor: not-allowed;
}

/* 记忆功能开关：flex布局，对齐文字与开关 */
.memory-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #666;
}


/* Markdown内容样式 */
.message-content {
  text-align: left;
}

.message-content >>> pre {
  white-space: pre-wrap; /* 关键：让代码自动换行 */
  background-color: #f6f8fa; /* 浅灰色背景，区分代码块 */
  border-radius: 5px;
  overflow-x: auto; /* 当代码过长时显示横向滚动条（可选） */
  font-size: 13px; /* 减小代码字体，节省空间 */
}

.message-content >>> code {
  font-family: 'Courier New', monospace;
  background-color: #e8f3ff; /* 浅蓝色背景，突出内联代码 */
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 13px;
}

.message-content >>> h1,
.message-content >>> h2,
.message-content >>> h3 {
  margin: 1em 0 0.5em;
  font-weight: bold;
}

.message-content blockquote {
  border-left: 4px solid #dfe2e5;
  /*color: #ffffff;*/
  padding: 0 1em;
  margin: 0 0 16px 0;
}

.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 16px;
}

.message-content th, .message-content td {
  border: 1px solid #dfe2e5;
  padding: 6px 13px;
}

.message-content tr {
  background-color: #fff;
  border-top: 1px solid #c6cbd1;
}

.message-content tr:nth-child(2n) {
  background-color: #f6f8fa;
}
</style>
